import MySQLdb
from index import *  
import json
db = MySQLdb.connect("localhost", "roartool", "NzAc6nDeE87i2rpZ", "roartool", charset='utf8' )
def sqlread():
       cursor = db.cursor()
       sql = "SELECT * FROM ruler \
       WHERE id = 1"
       try:
              cursor.execute(sql)
              results = cursor.fetchall()
              for item in results:
                     verf=action(item[2],item[3],item[4],item[5],item[6],int(item[9]),item[7])
                     print(verf)
              #verf=action(results[0][2],results[0][3],results[0][4],results[0][5],results[0][6],int(results[0][9]),results[0][7])

       except Exception as e:
        print("查询出错：case%s"%e)

       finally:
        # 关闭游标连接
              cursor.close()
        # 关闭数据库连接
              db.close()

def action(pool,types,value1,value2,value3,line,name):
       if(pool=="antpool"):
              data=json.loads(getinfo(pool,types,value1,value2,value3))
              if (int(data["data"]["last10m"])<line):
                     return('true')
              else:
                     return('low')
       elif(pool=="f2pool"):
              data=json.loads(getinfo(pool,types,value1,"",""))
              if (int(data["hashes_last_hour"])<line):
                     return('true')
              else:
                     return('low')
       elif(pool=="poolin"):
              data=json.loads(getinfo(pool,types,value1,value2,""))
              if (int(data["data"]["shares_15m"])<line):
                     return('true')
              else:
                     return('low')
       else:
             return("error")
# action("antpool","BTC","wikighome","f2204ac7dfa24c51b65f46014e34fe4a","e2a2797ce8d3493da7ec02ac1dc7072f",-1,'qwq')\
# action("f2pool","bitcoin","wikig16","","",1,'qwq')
sqlread()